<template>
  <div>
    <el-upload
      class="upload-demo"
      :headers="headers"
      :action="action"
      :on-success="handleAvatarSuccess"
      :auto-upload="false"
      :show-file-list="true"
      :on-change="handleChange"
      :data="params"
    >
      <el-button size="medium" type="primary">{{ label }}</el-button>
    </el-upload>
  </div>
</template>
<script>
export default {
  name: 'uploadExcel',
  props: {
    label: {
      default: '导入表格',
      type: String
    },
    params: {
      default: () => {},
      type: Object
    }
  },
  data() {
    return {
      token: '', //获取token
      // action: process.env.VUE_APP_BASE_API + '/web/basketballPlayer/importPlayer' //地址
      action: 'http://m.yundongshugenmatch.cn/api' + '/system/web/basketballPlayer/importPlayer', //地址
      headers: {
        Authorization: 'Bearer ' + sessionStorage.getItem('token')
      }
    }
  },
  created() {
    this.token = localStorage.getItem('SMHSWb_ADMIN_TOKEN')
  },
  methods: {
    handleChange(file) {
      console.log('file.raw', file.raw)
      this.$emit('ok', file.raw)
    },
    //上传成功
    handleAvatarSuccess(response) {
      this.$emit('ok', response)
    }
    // beforeAvatarUpload(file) {
    //   console.log('fa', file)
    //   return false
    // }
  }
}
</script>
